/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.mods.shooter.states;

import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial.CullHint;
import etherblocks.engine.JMonkeyUtil;
import etherblocks.engine.states.BaseAppState;
import etherblocks.mods.shooter.states.objects.*;

/**
 *
 * @author Carl
 */
public class WeaponAppState extends BaseAppState{

    public WeaponAppState(){
        
    }
    private ViewPort viewPort;
    private Node cameraNode;
    private WeaponObject weaponObject;
 
    @Override
    public void initialize(AppStateManager appStateManager, Application application){
        super.initialize(appStateManager, application);
        viewPort = application.getRenderManager().createMainView("WeaponViewPort", application.getCamera());
        viewPort.setEnabled(true);
        viewPort.setClearFlags(false, true, false);
        cameraNode = new Node();
        weaponObject = new WeaponObject(mainApplication);
        cameraNode.attachChild(weaponObject);
        DirectionalLight directionalLight = new DirectionalLight();
        directionalLight.setDirection(new Vector3f(-0.5f, -1, -0.5f).normalizeLocal());
        directionalLight.setColor(ColorRGBA.White.mult(0.5f));
        cameraNode.addLight(directionalLight);
        cameraNode.setCullHint(CullHint.Never);
        viewPort.attachScene(cameraNode);
        cameraNode.updateLogicalState(1);
        cameraNode.updateGeometricState();
    }
 
    @Override
    public void update(float lastTimePerFrame){
        cameraNode.setLocalTranslation(mainApplication.getCamera().getLocation());
        JMonkeyUtil.setLocalRotation(cameraNode, mainApplication.getCamera().getDirection());
        cameraNode.updateLogicalState(lastTimePerFrame);
    }
 
    @Override
    public void render(RenderManager rm){
        cameraNode.updateGeometricState();
    }

    public WeaponObject getWeaponObject(){
        return weaponObject;
    }
}